package tests;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import utils.AutoTestUtils;

import java.io.IOException;

public class ListPage extends AutoTestUtils {
    public static String url = "http://114.55.226.213:8080/list.html";

    public ListPage() {
        super(url);
    }


    public void searchSong(String songName) throws InterruptedException {
        // 指定音乐查询
        driver.findElement(By.cssSelector("#exampleInputName2")).clear();
        driver.findElement(By.cssSelector("#exampleInputName2")).sendKeys(songName);
        driver.findElement(By.cssSelector("#submit1")).click();

    }


    public void playSong() {
        // 播放音乐
        driver.findElement(By.cssSelector("#info > tr:nth-child(2) > td:nth-child(4) > button")).click();
    }

    // 收藏音乐
    public void lovedMusic() throws InterruptedException {
        driver.findElement(By.cssSelector("#info > tr:nth-child(2) > td:nth-child(5) > button:nth-child(2)")).click();
        Thread.sleep(1000);
        Alert alert = driver.switchTo().alert();
        //确认弹窗
        alert.accept();
    }

    public void uploadSong() throws InterruptedException, IOException {
        // 点击上传音乐按钮进去上传音乐页面
        driver.findElement(By.cssSelector("#body > div.container > div:nth-child(3) > a:nth-child(2)")).click();
        Thread.sleep(500);
        // 找到上传音乐按钮并上传文件
        WebElement ele = driver.findElement(By.cssSelector("#fileUpload"));
        ele.sendKeys("D:\\MusicProject\\Evan Call - Zoltraak.mp3");
        driver.findElement(By.cssSelector("#singer")).sendKeys("未知歌手");
        driver.findElement(By.cssSelector("#animeStyle")).click();
        driver.findElement(By.cssSelector("#submitBtn")).click();
        Thread.sleep(2000);
        Alert alert = driver.switchTo().alert();
        //确认弹窗
        alert.accept();
        Thread.sleep(5000);
        AutoTestUtils.getScreenshot("uploadSong");

    }

    public void deleteSong() {
        // 删除歌曲
        driver.findElement(By.cssSelector("#info > tr:nth-child(2) > td:nth-child(5) > button:nth-child(1)")).click();
        
    }


}
